﻿<?php
	Header("content-type: application/x-javascript");
	$secrets_file="GP_secrets.php";
	$settings_file="GP_settings.php";
	
	if(file_exists($settings_file))
		require($settings_file);
	if (isset($settings))
		$settings=unserialize(stripslashes($settings));
	else 
		$settings=default_settings();
		extract($settings);
	
	$roman=array( 0=>null,
				  1=>'I',
				  2=>'II',
				  3=>'III',
				  4=>'IV',
				  5=>'V', 
				  6=>'VI', 
				  7=>'VII', 
				  8=>'VIII', 
				  9=>'IX', 
				  10=>'X', 
				  11=>'XI', 
				  12=>'XII');		

/*
place ={
		infowin_html: content of infowindow,
		tooltip_html: content of tooltip,
		position:{lat:latitude, lng:longitude}
}
*/

	db_conn();
	$q=mysql_query("SELECT lat, lng, UNIX_TIMESTAMP(date) as date, brief, description FROM pins ORDER BY id DESC LIMIT 0,".$limit);
		
	while($row = mysql_fetch_assoc($q)) 
	{
		$row['brief']=str_replace (array("\n", "\r"), array("<br>"), htmlspecialchars($row['brief']));
		$row['description']=str_replace (array("\n", "\r"), array("<br>"), htmlspecialchars($row['description']));
		$nicedate=date ('j',$row['date']).' '.$roman[date('n', $row['date'])].' '.date('Y, H:i', $row['date']);
		echo 'places.push({infowin_html:"<h4>'.$nicedate.'</h4><div>'.$row['brief'].'</div><div>'.$row['description'].'</div>", tooltip_html:"<h4>'.$nicedate.'</h4><div>'.$row['brief'].'</div>Click for more..", position:{lat:'.$row['lat'].', lng:'.$row['lng'].'}});
';
	}


/*
places.push({infowin_html:"", tooltip_html:"<h3>Oak Park, Illinois</h3><div><stong>Population:</strong> 52k</div>Click for more..", position:{lat:x, lng:y}});
*/

function db_conn()
{
	global $secrets_file;
	require($secrets_file);
    if (!@mysql_connect($db_host, $db_user, $db_pass))
    {
	  die();
    }
    mysql_select_db($db_name) or die();
}
// Settings: generating default settings
function default_settings()
{
	$settings['api_key']='';
	$settings['map_center']['latitude']=51.85;
	$settings['map_center']['longtitude']=19.25;
	$settings['map_zoom']=5;
	$settings['map_type_id']="roadmap";
	$settings['limit']=100;
	return $settings;
}
?>